import { WidgetOption, WidgetType, WidgetStyle } from '@/types'
import WidgetRemark from './WidgetRemark.vue'
import RemarkSetting from './RemarkSetting.vue'
import { getTextareaTextTips, initTextData, rawTextCreator, rawTextGetter } from '../input'

/** 签署备注 */
export default {
  key: 'remark',
  name: '签署备注',
  type: WidgetType.REMARK,
  style: WidgetStyle.SIGN,
  icon: 'fa-icon-widget-remark',
  width: 220,
  height: 64,
  minWidth: 100,
  minHeight: 30,

  /**
   * 允许调整大小
   * 1. 设置模式
   * 2. 使用模式未指定位置
   */
  resizable: widget => widget.isSet || (widget.isUse && !widget.isFixed),

  component: WidgetRemark,
  settingComponent: RemarkSetting,

  /** 初始控件数据 */
  init: initTextData,

  /** 签署控件使用校验 */
  usingValidate(widget) {
    if (!widget.value) return `请输入${widget.option.name}`
  },

  labelTips(widget) {
    // 设置和使用模式显示可输入长度
    if (!(widget.isSet || widget.isUse)) return ''

    return getTextareaTextTips(widget)
  },

  rawWidgetCreator: rawTextCreator,

  rawFieldGetter: rawTextGetter
} as WidgetOption
